<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('生产出片管理')" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="form">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label class="control-label is-required">月份：</label>
                                <input type="text" class="input-sm" id="timeFlag" name="timeFlag" required/>
                            </li>
                            <li>
                                <label>产品类型：</label>
                                <select name="materialType" th:with="type=${@dict.getType('datasta_part_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" class="input-sm" id="partName" name="partName"/>
                            </li>
                            <li>
                                <label>批次类型：</label>
                                <select name="lotType" th:with="type=${@dict.getType('lot_type')}" id="lot_select">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label class="control-label">是否参与计算：</label>
                                <select name="ifJoinCalculate" th:with="type=${@dict.getType('yes_no_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>客户名称：</label>
                                <select name="customerName" th:with="si=${cuslist}" id="cus_select">
                                    <option value="">所有</option>
                                    <option th:each="cus : ${si}" th:text="${cus.customerName}" th:value="${cus.customerName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>卡号：</label>
                                <input type="text" class="input-sm" id="lotId" name="lotId"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="searchpartoutimesta()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary multiple disabled" onclick="$.operate.edit();" shiro:hasPermission="promanage:partoutimesta:getridof">
                    <i class="fa fa-remove"></i> 批量剔除
                </a>
                <a class="btn btn-success multiple disabled" onclick="cancelGetRidOf()" shiro:hasPermission="promanage:partoutimesta:cancelgetridof">
                    <i class="fa fa-reply"></i> 取消剔除
                </a>
                <a class="btn btn-info" onclick="calculateCT()" shiro:hasPermission="promanage:partoutimesta:calculatect">
                    <i class="fa fa-calculator"></i> 计算CT
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="promanage:partoutimesta:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        const prefix = ctx + "promanage/partoutimesta";
        var is_over_standard = [[${@dict.getType('is_over_standard')}]];
        var tableinit = [[${tableinit}]];
        var columnArrys = [
            {
                checkbox: true
            },
            {
                field : 'id',
                title : '编号',
                visible: false
            },
            {
                field : 'timeFlag',
                title : '日期时间标识'
            },
            {
                field : 'materialType',
                title : '产品类型',
                sortable: true
            },
            {
                field : 'partName',
                title : '产品名称',
                sortable: true
            },
            {
                field : 'customerName',
                title : '客户名称',
                sortable: true
            },
            {
                field : 'lotType',
                title : '批次类型'
            },
            {
                field: 'lotId',
                title: '批号'
            },
            {
                field: 'transType',
                title: '事务类型'
            },
            {
                field: 'qty',
                title: '数量',
                sortable: true
            },
            {
                field: 'lotStartTime',
                title: '批次开始时间',
                sortable: true
            },
            {
                field: 'lotShipTime',
                title: '批次结束时间',
                sortable: true
            },
            {
                field: 'lotConsumeDays',
                title: '批次生产耗时(天)',
                sortable: true
            },
            {
                field: 'ifJoinCalculate',
                title: '是否参与计算',
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(is_over_standard, value);
                },
                sortable: true
            },
            {
                field: 'exclusionReason',
                title: '剔除原因'
            }
        ];

        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            updateUrl: prefix + "/edit/{id}",
            modalName: "生产出片管理",
            columns: columnArrys,
            sortName: "lotStartTime",
            sortOrder: "asc",
            pageList: [10, 20, 30, 50],
            sidePagination: "client",
            showHeader: true
        };

        $(function() {
            // 初始化选择月份
            layui.use('laydate', function(){
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#timeFlag',
                    type: 'month',
                    value: new Date()
                });
            });
        });

        function searchpartoutimesta() {
            if (tableinit) {
                $.table.init(options);
                tableinit = false;
            } else {
                $.table.search();
            }
        }

        function cancelGetRidOf() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("请确认取消剔除?", function() {
                var url = prefix + "/cancelgetridof";
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }

        // 计算ct
        function calculateCT() {
            var url = prefix + "/calculatect";
            var timflag = $('#timeFlag').val();
            var data = { "timeflag": timflag };
            var ajaxconfig = {
                url: url,
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍候...");
                },
                success: function(result) {
                    if (null === result) {
                        return;
                    }
                    if (result.code === web_status.SUCCESS) {
                        $.modal.alertSuccess("计算成功！");
                    } else if (result.code === web_status.WARNING) {
                        $.modal.alertWarning(result.msg);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                complete: function () {
                    $.modal.closeLoading();
                }
            };
            $.ajax(ajaxconfig);
        }
    </script>
</body>
</html>